﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DeepZoomPivotConstructor.VisualLib;
using System.Drawing;

namespace t_VisualLib
{
    [TestClass]
    public class t_VisualUtilities
    {
        [TestMethod]
        public void TestNOCUCounting()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 150, Color.Black);
            Assert.AreEqual(0, v.CountNumberOfComposableUnits(), "There were no CU's!");
        }

        [TestMethod]
        public void TestSimpleCUCounting()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 150, Color.Black);
            v.SetAsComposableUnit(null);
            Assert.AreEqual(1, v.Count(), "Simple CU in there");

            VisualHolder vh = new VisualHolder();
            vh.AddImage(v);
            vh.AddImage(new VisualBitmapImage(2.0, 2.0, 150, Color.Blue));
            Assert.AreEqual(1, vh.CountNumberOfComposableUnits(), "Nested single CU should be still just one!");

            VisualHolder vh2 = new VisualHolder();
            vh2.AddImage(new VisualBitmapImage(4.0, 3.0, 100, Color.Black));
            vh2.SetAsComposableUnit(null);

            VisualHolder vh3 = new VisualHolder();
            vh3.AddImage(vh2);
            vh3.AddImage(vh);
            Assert.AreEqual(2, vh3.CountNumberOfComposableUnits(), "Two CU's next to each other, should be counted as 2!");
        }

        [TestMethod]
        public void TestNestedCUCounting()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 150, Color.Black);
            v.SetAsComposableUnit(null);

            VisualHolder vh = new VisualHolder();
            vh.AddImage(v);
            vh.SetAsComposableUnit(null);

            Assert.AreEqual(1, vh.CountNumberOfComposableUnits(), "Nested CU's don't count - only the top level one");
        }

        [TestMethod]
        public void TestCountCUsThatAreReal()
        {
            Visual.VisualInfo metaData = new Visual.VisualInfo();
            VisualItemPlaceHolder ip = new VisualItemPlaceHolder(1.0, 2.0, new System.IO.FileInfo("junk.xml"), metaData, null);

            VisualBitmapImage bmi = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            bmi.SetAsComposableUnit(null);

            VisualHolder vh = new VisualHolder();
            vh.AddImage(ip);
            vh.AddImage(bmi);

            Assert.AreEqual(2, vh.CountNumberOfComposableUnits(), "Expected both item and image would be CUs");
            Assert.AreEqual(1, vh.CountNumberOfComposableUnits(v => v.GetType() != typeof(VisualItemPlaceHolder)), "Condition didn't seem to work!");
        }
    }
}
